/**
 * Created by frank on 2017/9/11.
 */
;(function(window){
   //封闭的私用变量
    var $id = function(id){
        if (typeof id === 'object') {
            return id;
        } else {
            return document.getElementById(id);
        }
    },
        $tag = function(tagName){
            return document.getElementsByTagName(tagName);
        },
        loadJs = function(path,callback){
            var script = document.createElement('script');
            script.src = path;
            document.head.appendChild(script);
            var that = this;
            script.onload = function(){
                callback.call(that);
            }

        }

   //相当于var id=10,tag=20;
    // var id = 10;
    // var tag = 20;

    var myFocus = function(setting){
            return new myFocus.constr(setting);
    };

    //extend 扩充这个对象的属性
    myFocus.extend = function(){//{a:'frank',b:'tom',c:function(){}}
        var dest = myFocus;
        for(var i in arguments){
            for(var item in arguments[i]){
                dest[item] = arguments[i][item];
            }
        }
    }

    //静态属性
    myFocus.extend({
        constr:function(setting){
            this.ball = document.getElementById(setting.ballid);
            this.btn = document.getElementById(setting.clickbtn);
            //判断有没有pa属性
            if (setting.pa){
                loadJs.call(this,setting.pa, this.bEvent);
            } else {
                this.bEvent();
            }


        },
        set:function(setting){
            var obj =  myFocus(setting);;

        }
    });

    myFocus.fn = myFocus.constr.prototype;
    myFocus.fn.extend = function(){//{a:'frank',b:'tom',c:function(){}}
        var dest = myFocus.fn;
        for(var i in arguments){
            for(var item in arguments[i]){
                dest[item] = arguments[i][item];
            }
        }
    }

    //原型对象中的属性
    myFocus.fn.extend({
        bEvent:function(){
            this.btn.onclick = this.move;
        },
        move:function(){
           function domove(){
               this.ball.style.marginLeft = parseInt(this.ball.style.marginLeft)+5+'px';
           }
           this.t = setInterval(domove,20);
        }
    })

    // myFocus.set = function(setting){
    //     console.log(setting);
    // }
    // myFocus.set = function(setting){
    //     console.log(setting);
    // }
    //
    // myFocus.prototype.say = function(){
    //     alert('say')
    // }


    window.myFocus = myFocus;


})(window);